//$Id: TileResult.java 215 2010-11-07 16:40:46Z vincentngik $

package builders;

/**
 * this is used to communicate to Logic the results of the event triggered by the player when the player landed on the tile
 * 
 * @author Vincent
 */
public class TileResult {

	private int amountToIncrease;
	private Player.Resource resourceThatIsAffected;
	private String tileDescription;

	/*
	 * this is set to true if the tile is a homeBase, otherwise this is set to false
	 */
	private boolean isHomeBase;

	/*
	 * this is set to true if the numberOfActionPointsLeft input to execute(int) is out of the allowed range.
	 */
	private boolean errorPresent = false;

	/**
	 * This is the constructor used by the Tile class.
	 * 
	 * @param resource
	 * @param amountToIncrease
	 * @param tileDescription
	 */
	public TileResult(Player.Resource resource, int amountToIncrease, String tileDescription) {
		this.resourceThatIsAffected = resource;
		this.amountToIncrease = amountToIncrease;
		this.tileDescription = tileDescription;
		this.isHomeBase = false;
	}

	/**
	 * This is the constructor used by the HomeBase class.
	 * 
	 * @param tileDescription
	 */
	public TileResult(String tileDescription) {
		this.tileDescription = tileDescription;
		this.isHomeBase = true;
	}

	/**
	 * This is the constructor that will be called when the input to execute(int) is out of the allowed range.
	 * This prevents any of the player from using a wrong input to call execute(int). 
	 * 
	 * @param errorPresent	specify that error is present
	 */
	public TileResult(boolean errorPresent) {
		this.errorPresent = errorPresent;
	}

	/**
	 * @return	the amount the affected resource, specified by resourceThatIsAffected, has changed
	 */
	public int getAmountToIncrease(){
		if (!isHomeBase){
			return amountToIncrease;
		} else {
			/*
			 * this method should not be called:
			 * 1) as the TileResult object is for a homeBase or
			 * 2) the TileResult is created by an error input to execute(int)
			 * 
			 * return -1 to indicate that there is an error.
			 */
			return -1; 
		}
	}

	/**
	 * @return	the resource that is affected
	 */
	public Player.Resource getResourceThatIsAffected(){
		if (!isHomeBase){
			return resourceThatIsAffected;
		} else {
			/*
			 * this method should not be called:
			 * 1) as the TileResult object is for a homeBase or
			 * 2) the TileResult is created by an error input to execute(int)
			 * 
			 * return null to indicate that there is an error.
			 */
			return null;
		}
	}

	/**
	 * @return	the description of what the tile has done if it is not a homeBase, otherwise this will be the description that informs the player that the player has landed on a homeBase
	 */
	public String getTileDescription(){
		return tileDescription;	
	}

	/**
	 * @return true if the TileResult is for a homeBase, otherwise false
	 */
	public boolean getIsHomeBase(){
		return isHomeBase;
	}
	
	/**
	 * @return true if the numberOfActionPointsLeft input to execute(int) is out of the allowed range, otherwise false
	 */
	public boolean getErrorPresent(){
		return errorPresent;
	}
}